﻿using SRB.Tg.DrawingStandard;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public  class AviationStructure
    {
        public static void DrawSteelTower(Database db, Point2d stpointLM, ref Extents2d ext,double twHeight, double topWidth,double slope, double brslope, System.Data.DataRow dr, string layerName = "H细线")
        {
            double cushionH =  double.Parse(dr["hc_center_distance"].ToString()) * 100;
            double hcSpan =double.Parse( dr["cross_brace_h_span"].ToString());
            hcSpan = hcSpan * 100;
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, topWidth * 0.5 * brslope), stpointLM.C2D(-topWidth * 0.5, -cushionH), ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -topWidth * 0.5 * brslope), stpointLM.C2D(topWidth * 0.5, -cushionH), ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, - cushionH), pt1, ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -cushionH), pt2, ref ext, layerName);
            int hcNum = (int)(twHeight / hcSpan);
            PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            for (int m = 1; m < hcNum; m++)
            {
                Point2d p1 = stpointLM.C2D(-topWidth * 0.5 - hcSpan*m * slope, -cushionH - hcSpan * m);
                Point2d p2 = stpointLM.C2D(topWidth * 0.5 + hcSpan * m * slope, -cushionH - hcSpan * m);
                PLPloter.AddLine(db, p1, p2, ref ext, layerName);
            }           
        }

        public static void DrawGemstoneShapeSteelTower(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope, System.Data.DataRow dr, string layerName = "H细线",bool isLastTower=false)
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString()) * 100;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = int.Parse(dr["gemstone_slope"].ToString());
                max = int.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }          
            Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, topWidth*0.5 * brslope), stpointLM.C2D(-topWidth * 0.5, -cushionH), ref ext, layerName);
            PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -topWidth * 0.5 * brslope), stpointLM.C2D(topWidth * 0.5, -cushionH), ref ext, layerName);
            Line lineL = PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, -cushionH), pt1, ref ext, layerName);
            Line lineR = PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -cushionH), pt2, ref ext, layerName);
            PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            double h = twHeight * 0.01 - cushionH*0.01; 
            String[] segments = gemstoneSegments.Replace("（","").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                //double htemp = 0;
                //for (int i = 0; i < segmentList.Count; i++)
                //{
                //    htemp += segmentList[i];
                //    double seg = h - (htemp - segmentList[i]);
                //    if (htemp > h)
                //    {
                //        if (seg > 0)
                //        {
                //            segmentLst.Add(seg);
                //            h = seg + (htemp - segmentList[i]);
                //        }
                //        break;
                //    }
                //    else
                //    {
                //        segmentLst.Add(segmentList[i]);
                //    }
                //}
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            //segmentLst.Add(seg);
                            //h = seg + (htemp - segmentList[i]);
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                //segmentLst.remove(segmentLst.size()-1);
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        //if (i == segmentList.Count - 1)
                        //{
                        //    seg = h - (htemp - segmentList[i]) + segmentList[i];
                        //    segmentLst.Add(seg);
                        //}
                        //else
                        //    segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                            seg = h - htemp + segmentList[i];
                            segmentLst.Add(seg);
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }
            #endregion

            //double slopeW = double.Parse(dr["slope_w"].ToString()); ;// 0.025;
            //double slopeL = double.Parse(dr["slope_l"].ToString());//0.125*0.5;

            Point2d stPt = stpointLM.C2D(0,-cushionH);
            double ycurT = 0;
            double ycurB = 0;

            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i] ;
                ycurB += seg * 100;
                ycurT = ycurB - seg * 100;
                // 顶部端点
                Line lineT = new Line(stPt.C3D(-topWidth*0.5,-ycurT), stPt.C3D(topWidth * 0.5, - ycurT));
                Line lineB = new Line(stPt.C3D(-topWidth * 0.5, -ycurB), stPt.C3D(topWidth * 0.5, - ycurB));

                Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
                Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);
                Point3d ptLB = MathExtensions.GetIntersection(lineL, lineB);
                Point3d ptRB = MathExtensions.GetIntersection(lineR, lineB);

                if(i==1)
                {
                    if (!isLastTower)
                    {
                        Point2d styPt1 = stpointLM.C2D(-topWidth * 1.5, topWidth * 1.5 * brslope);
                        Point2d styPt2 = stpointLM.C2D(topWidth * 1.5, -topWidth * 1.5 * brslope);

                        PLPloter.AddLine(db, ptLT.C2D(), styPt1, ref ext, layerName);
                        PLPloter.AddLine(db, ptRT.C2D(), styPt2, ref ext, layerName);
                    }
                }

                double scaleTen = 1 / 2.000;
      
                Point2d ptTMid = stPt.C2D(0,-ycurT);
                Point2d ptBMid = stPt.C2D(0, -ycurB);
                if (seg <= max)
                {
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                }
                else  //if (seg > min && seg <= max)
                {
                    scaleTen = 1 / 2.000;
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                    Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                    Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                    Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                    Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                    PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);
                }
                //else
                //{
                //    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                //    scaleTen = 1 / 3.000;
                //    Point3d ptMainL = GeTools.DivPoint(ptLT, ptLB,3);
                //    Point3d ptMainR = GeTools.DivPoint(ptRT, ptRB,3);
                //    Point3d ptL = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3);
                //    Point3d ptR = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3);
                //    PLPloter.AddLine(db, ptMainL.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR.C2D(), ptR.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptRT.C2D(), ptR.C2D(), ref ext, layerName);
                //    scaleTen = 2 / 3.000;
                //    Point3d ptMainL2 = GeTools.DivPoint(ptLT, ptLB, 3, true);
                //    Point3d ptMainR2 = GeTools.DivPoint(ptRT, ptRB, 3, true);
                //    Point3d ptL2 = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3, true);
                //    Point3d ptR2 = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3, true);

                //    PLPloter.AddLine(db, ptMainL2.C2D(), ptL2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR2.C2D(), ptR2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptL2.C2D(), ptMainL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptR2.C2D(), ptMainR.C2D(), ref ext, layerName);
                //}
                
            }
        }

        public static void DrawYGemstoneShapeSteelTower(Database db, Point2d stpointLM, ref Extents2d ext, double twHeight, double topWidth, double slope, double brslope, System.Data.DataRow dr, string layerName = "H细线")
        {
            double cushionH = double.Parse(dr["hc_center_distance"].ToString())*100;
            string gemstoneSegments = dr["gemstone_shape_segments"].ToString();
            double min = 3, max = 7;
            try
            {
                min = double.Parse(dr["gemstone_slope"].ToString());
                max = double.Parse(dr["gemstone_fifteen_slope"].ToString());
            }
            catch { }
            double yHeight= double.Parse(dr["yshape_height"].ToString())*100 ;
            double ySegLen = double.Parse(dr["yshape_segment_length"].ToString())*100;
            int  segNum= int.Parse(dr["yshape_segment_number"].ToString());
            string yBHeightLayout = dr["yshape_bottom_height_layout"].ToString();
            double bottomY= string.IsNullOrWhiteSpace(dr["bottom_y_length"].ToString())?0: double.Parse(dr["bottom_y_length"].ToString()) * 100;
            double newL = bottomY <= 0 ? topWidth * 0.5 + (twHeight - cushionH) * slope : bottomY + (twHeight * 0.01 - yHeight * 0.01) *slope;
            String[] yHStr = yBHeightLayout.Split('+');
            double hy1 = 3*100, hy2 = 2.6*100;
            if (yHStr.Length > 0)
            {
                hy1 = Double.Parse(yHStr[0]) * 100;
                if (yHStr.Length > 1)
                    hy2 = Double.Parse(yHStr[1]) * 100;
            }

            //double slopeW = double.Parse(dr["slope_w"].ToString()); ;// 0.025;
            //double slopeL = double.Parse(dr["slope_l"].ToString());//0.125*0.5;
            //Point2d pt1 = stpointLM.C2D(-topWidth * 0.5 - (twHeight - cushionH) * slope, -twHeight);
            //Point2d pt2 = stpointLM.C2D(topWidth * 0.5 + (twHeight - cushionH) * slope, -twHeight);
            Point2d pt1 = stpointLM.C2D(-newL, -twHeight);
            Point2d pt2 = stpointLM.C2D(newL, -twHeight);
            //PLPloter.AddLine(db, stpointLM.C2D(-topWidth * 0.5, topWidth * 0.5 * brslope), stpointLM.C2D(-topWidth * 0.5, -cushionH), ref ext, layerName);
            //PLPloter.AddLine(db, stpointLM.C2D(topWidth * 0.5, -topWidth * 0.5 * brslope), stpointLM.C2D(topWidth * 0.5, -cushionH), ref ext, layerName);


            double h = twHeight * 0.01 - yHeight * 0.01;
            String[] segments = gemstoneSegments.Replace("（", "").Replace("）", "").Replace("(", "").Replace(")", "").Split('+');
            List<Double> segmentList = new List<double>();
            List<Double> segmentLst = new List<double>();
            double totalH = 0;
            #region 节段解析
            for (int i = 0, exLen = segments.Length; i < exLen; i++)
            {
                //是否包含相同节段，也就是2*5类型
                if (segments[i].Contains("*"))
                {
                    String[] sp = segments[i].Split('*');
                    int m = int.Parse(sp[0]);
                    double v = Double.Parse(sp[1]);
                    for (int j = 0; j < m; j++)
                    {
                        segmentList.Add(v);
                        totalH += v;
                    }
                }
                else
                {
                    if (Double.Parse(segments[i]) > 0)
                    {
                        segmentList.Add(Double.Parse(segments[i]));
                        totalH += Double.Parse(segments[i]);
                    }
                    else
                    {
                        segmentList.Add(0.0);
                    }
                }
            }
            if (h > totalH)
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    if (i == segmentList.Count - 1)
                    {
                        double seg = h - (htemp - segmentList[i]);
                        segmentLst.Add(seg);
                    }
                    else
                    {
                        segmentLst.Add(segmentList[i]);
                    }
                }
            }
            else
            {
                double htemp = 0;
                for (int i = 0; i < segmentList.Count; i++)
                {
                    htemp += segmentList[i];
                    double seg = h - (htemp - segmentList[i]);
                    if (htemp > h)
                    {
                        if (seg > 0)
                        {
                            //segmentLst.Add(seg);
                            //h = seg + (htemp - segmentList[i]);
                            if (i < segmentList.Count - 1)
                            {
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                            else
                            {
                                //segmentLst.remove(segmentLst.size()-1);
                                //seg = h - (htemp - segmentList[i]);
                                //segmentLst.Add(seg);
                                seg = h - (htemp - segmentList[i]);
                                seg = seg + segmentList[i];
                                segmentLst.Remove(segmentLst[segmentLst.Count - 1]);
                                segmentLst.Add(seg);
                            }
                        }
                        break;
                    }
                    else
                    {
                        //segmentLst.Add(segmentList[i]);
                        if (i == segmentList.Count - 1)
                        {
                                seg = h - htemp + segmentList[i];
                                segmentLst.Add(seg);                          
                        }
                        else
                        {
                            segmentLst.Add(segmentList[i]);
                            if (htemp == h)
                                break;
                        }
                    }
                }
            }
            #endregion


            #region Y形
            Point2d styPt1 = stpointLM.C2D(-topWidth * 4.5, topWidth * 4.5 * brslope);
            Point2d styPt2 = stpointLM.C2D(topWidth * 4.5, -topWidth * 4.5 * brslope);
            //宝石底部宽度
            double btWidth= topWidth + (yHeight - cushionH) * slope * 2;
            Point2d yPt1 = stpointLM.C2D(-btWidth * 0.5, -yHeight);
            Point2d yPt2 = stpointLM.C2D(btWidth * 0.5,  -yHeight);
            Point2d ybtMidPt = stpointLM.C2D(0, -yHeight+hy1+hy2);
            //Point2d ybMidPt = stpointLM.C2D(0, -yHeight + hy1);
            //外轮廓
            PLPloter.AddLine(db, styPt1.C2D(), yPt1, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), yPt2, ref ext, layerName);
            //内轮廓
            PLPloter.AddLine(db, styPt1.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, styPt2.C2D(), ybtMidPt, ref ext, layerName);
            //Y搭接
            //PLPloter.AddLine(db, ybMidPt.C2D(), yPt1, ref ext, layerName);
            //PLPloter.AddLine(db, ybMidPt.C2D(), yPt2, ref ext, layerName);
            //PLPloter.AddLine(db, ybMidPt.C2D(), ybtMidPt, ref ext, layerName);

            Point3d yPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), segNum +1);
            Point3d yPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), segNum +1);


            PLPloter.AddLine(db, yPtL.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPtR.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPt1.C2D(), ybtMidPt, ref ext, layerName);
            PLPloter.AddLine(db, yPt2.C2D(), ybtMidPt, ref ext, layerName);

            //PLPloter.AddLine(db, yPtL.C2D(), ybMidPt, ref ext, layerName);
            //PLPloter.AddLine(db, yPtR.C2D(), ybMidPt, ref ext, layerName);

            Point3d yLastPtL = GeTools.DivPoint(yPt1.C3D(), styPt1.C3D(), segNum + 1);
            Point3d yLastPtR = GeTools.DivPoint(yPt2.C3D(), styPt2.C3D(), segNum + 1);
            //Y悬臂
            for (int i=1;i<=segNum;i++)
            {
                Point3d yLOutPt =GeTools.CalPoint(yPt1.C3D(), styPt1.C3D(), (i + 1) / (segNum + 1.000));
                Point3d yLInnerPt = GeTools.CalPoint(ybtMidPt.C3D(), styPt1.C3D(), (i) / (segNum * 1000 * 0.001));

                Point3d yROutPt = GeTools.CalPoint(yPt2.C3D(), styPt2.C3D(), (i + 1) / (segNum + 1.000));
                Point3d yRInnerPt = GeTools.CalPoint(ybtMidPt.C3D(), styPt2.C3D(), (i) / (segNum*1000*0.001));


                PLPloter.AddLine(db, yLOutPt.C2D(), yLInnerPt.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yROutPt.C2D(), yRInnerPt.C2D(), ref ext, layerName);



                PLPloter.AddLine(db, yLastPtL.C2D(), yLInnerPt.C2D(), ref ext, layerName);
                PLPloter.AddLine(db, yLastPtR.C2D(), yRInnerPt.C2D(), ref ext, layerName);
                yLastPtL = yLOutPt;
                yLastPtR = yROutPt;
            }
            #endregion

            #region 钢塔下部宝石结构
            topWidth = bottomY>0?bottomY: topWidth + (yHeight  - cushionH) * slope * 2;
            Point2d stPt = stpointLM.C2D(0, -yHeight);
            Line lineL = PLPloter.AddLine(db, stPt.C2D(-topWidth * 0.5, 0), pt1, ref ext, layerName);
            Line lineR = PLPloter.AddLine(db, stPt.C2D(topWidth * 0.5, 0), pt2, ref ext, layerName);
            PLPloter.AddLine(db, pt1, pt2, ref ext, layerName);
            double ycurT = 0;
            double ycurB = 0;

            for (int i = 0; i < segmentLst.Count; i++)
            {
                double seg = segmentLst[i];
                ycurB += seg * 100;
                ycurT = ycurB - seg * 100;
                // 顶部端点
                Line lineT = new Line(stPt.C3D(-topWidth * 0.5, -ycurT), stPt.C3D(topWidth * 0.5, -ycurT));
                Line lineB = new Line(stPt.C3D(-topWidth * 0.5, -ycurB), stPt.C3D(topWidth * 0.5, -ycurB));

                Point3d ptLT = MathExtensions.GetIntersection(lineL, lineT);
                Point3d ptRT = MathExtensions.GetIntersection(lineR, lineT);
                Point3d ptLB = MathExtensions.GetIntersection(lineL, lineB);
                Point3d ptRB = MathExtensions.GetIntersection(lineR, lineB);
                double scaleTen = 1 / 2.000;

                Point2d ptTMid = stPt.C2D(0, -ycurT);
                Point2d ptBMid = stPt.C2D(0, -ycurB);
                if (seg <= max)
                {
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                }
                else 
                {
                    scaleTen = 1 / 2.000;
                    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                    Point3d ptMainMidL = GeTools.DivPoint(ptLT, ptLB);
                    Point3d ptMainMidR = GeTools.DivPoint(ptRT, ptRB);
                    Point3d ptMidL = GeTools.DivPoint(ptTMid.C3D(), ptLB);
                    Point3d ptMidR = GeTools.DivPoint(ptTMid.C3D(), ptRB);
                    PLPloter.AddLine(db, ptMainMidL.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptMainMidR.C2D(), ptMidR.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptLT.C2D(), ptMidL.C2D(), ref ext, layerName);
                    PLPloter.AddLine(db, ptRT.C2D(), ptMidR.C2D(), ref ext, layerName);
                }
                //else
                //{
                //    PLPloter.AddLine(db, ptLB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptRB.C2D(), ptTMid, ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptRT.C2D(), ref ext, layerName);
                //    scaleTen = 1 / 3.000;
                //    Point3d ptMainL = GeTools.DivPoint(ptLT, ptLB, 3);
                //    Point3d ptMainR = GeTools.DivPoint(ptRT, ptRB, 3);
                //    Point3d ptL = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3);
                //    Point3d ptR = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3);
                //    PLPloter.AddLine(db, ptMainL.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR.C2D(), ptR.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptLT.C2D(), ptL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptRT.C2D(), ptR.C2D(), ref ext, layerName);
                //    scaleTen = 2 / 3.000;
                //    Point3d ptMainL2 = GeTools.DivPoint(ptLT, ptLB, 3, true);
                //    Point3d ptMainR2 = GeTools.DivPoint(ptRT, ptRB, 3, true);
                //    Point3d ptL2 = GeTools.DivPoint(ptTMid.C3D(), ptLB, 3, true);
                //    Point3d ptR2 = GeTools.DivPoint(ptTMid.C3D(), ptRB, 3, true);

                //    PLPloter.AddLine(db, ptMainL2.C2D(), ptL2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptMainR2.C2D(), ptR2.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptL2.C2D(), ptMainL.C2D(), ref ext, layerName);
                //    PLPloter.AddLine(db, ptR2.C2D(), ptMainR.C2D(), ref ext, layerName);
                //}

            }
            #endregion
        }

    }
}
